package com.mh.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.validator.constraints.NotEmpty;

import com.mh.web.utils.DateJsonDeserializer;
import com.mh.web.utils.DateJsonSerializer;
import com.mh.web.utils.DateUtils;

/**
 * 
 * @ModelCoreReference [platform:/resource/demo-mh/.springDSL/com/mh/domain/Customer.datatype]
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllCustomers", query = "select myCustomer from Customer myCustomer"),
		@NamedQuery(name = "findCustomerByAddress", query = "select myCustomer from Customer myCustomer where myCustomer.address = ?1"),
		@NamedQuery(name = "findCustomerByAddressContaining", query = "select myCustomer from Customer myCustomer where myCustomer.address like ?1"),
		@NamedQuery(name = "findCustomerByBirthday", query = "select myCustomer from Customer myCustomer where myCustomer.birthday = ?1"),
		@NamedQuery(name = "findCustomerByCity", query = "select myCustomer from Customer myCustomer where myCustomer.city = ?1"),
		@NamedQuery(name = "findCustomerByCityContaining", query = "select myCustomer from Customer myCustomer where myCustomer.city like ?1"),
		@NamedQuery(name = "findCustomerByCreatedBy", query = "select myCustomer from Customer myCustomer where myCustomer.createdBy = ?1"),
		@NamedQuery(name = "findCustomerByCreatedByContaining", query = "select myCustomer from Customer myCustomer where myCustomer.createdBy like ?1"),
		@NamedQuery(name = "findCustomerByCreatedOn", query = "select myCustomer from Customer myCustomer where myCustomer.createdOn = ?1"),
		@NamedQuery(name = "findCustomerByEmail", query = "select myCustomer from Customer myCustomer where myCustomer.email = ?1"),
		@NamedQuery(name = "findCustomerByEmailContaining", query = "select myCustomer from Customer myCustomer where myCustomer.email like ?1"),
		@NamedQuery(name = "findCustomerByFirstName", query = "select myCustomer from Customer myCustomer where myCustomer.firstName = ?1"),
		@NamedQuery(name = "findCustomerByFirstNameContaining", query = "select myCustomer from Customer myCustomer where myCustomer.firstName like ?1"),
		@NamedQuery(name = "findCustomerById", query = "select myCustomer from Customer myCustomer where myCustomer.id = ?1"),
		@NamedQuery(name = "findCustomerByLastName", query = "select myCustomer from Customer myCustomer where myCustomer.lastName = ?1"),
		@NamedQuery(name = "findCustomerByLastNameContaining", query = "select myCustomer from Customer myCustomer where myCustomer.lastName like ?1"),
		@NamedQuery(name = "findCustomerByModifiedBy", query = "select myCustomer from Customer myCustomer where myCustomer.modifiedBy = ?1"),
		@NamedQuery(name = "findCustomerByModifiedByContaining", query = "select myCustomer from Customer myCustomer where myCustomer.modifiedBy like ?1"),
		@NamedQuery(name = "findCustomerByModifiedOn", query = "select myCustomer from Customer myCustomer where myCustomer.modifiedOn = ?1"),
		@NamedQuery(name = "findCustomerByPrimaryKey", query = "select myCustomer from Customer myCustomer where myCustomer.id = ?1") })
@Table(schema = "MHTEST", name = "CUSTOMER")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "demo-mh/com/mh/domain", name = "Customer")
@XmlRootElement(namespace = "demo-mh/com/mh/domain")
public class Customer implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_customer")
	@SequenceGenerator(name = "seq_customer", sequenceName = "seq_customer")
	Integer id;

	/**
	 */

	@Column(name = "EMAIL", length = 60, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=60,  message="{com.vit.tamanho.maximo}")
	String email;

	/**
	 */

	@Column(name = "FIRST_NAME", length = 30, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String firstName;

	/**
	 */

	@Column(name = "LAST_NAME", length = 30, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String lastName;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "BIRTHDAY", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Date birthday;

	/**
	 */

	@Column(name = "ADDRESS", length = 40)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=40,  message="{com.vit.tamanho.maximo}")
	String address;

	/**
	 */

	@Column(name = "CITY", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=20,  message="{com.vit.tamanho.maximo}")
	String city;

	/**
	 */

	@Column(name = "CREATED_BY", length = 30, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String createdBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_ON", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Date createdOn;

	/**
	 */

	@Column(name = "MODIFIED_BY", length = 30)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String modifiedBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFIED_ON")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Date modifiedOn;

	/**
	 */
	
	@OneToMany(mappedBy = "customer", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<com.mh.domain.Invoice> invoices;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */

	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 */
	public String getEmail() {
		return this.email;
	}

	/**
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 */
	public String getFirstName() {
		return this.firstName;
	}

	/**
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 */
	public String getLastName() {
		return this.lastName;
	}

	/**
	 */
	@JsonDeserialize(using=DateJsonDeserializer.class)
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	/**
	 */
	@JsonSerialize(using=DateJsonSerializer.class)	
	public Date getBirthday() {
		return this.birthday;
	}
	
	
	public void setBirthdayString(String birthday) {
		this.birthday = DateUtils.convertToDate(birthday);
	}

	/**
	 */
		
	public String getBirthdayString() {
		return DateUtils.convertToString(this.birthday);
	}

	

	/**
	 */
	
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 */
	public String getAddress() {
		return this.address;
	}

	/**
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 */
	public String getCity() {
		return this.city;
	}

	/**
	 */
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 */
	public String getCreatedBy() {
		return this.createdBy;
	}

	/**
	 */
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	/**
	 */
	public Date getCreatedOn() {
		return this.createdOn;
	}

	/**
	 */
	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	/**
	 */
	public String getModifiedBy() {
		return this.modifiedBy;
	}

	/**
	 */
	public void setModifiedOn(Date modifiedOn) {
		this.modifiedOn = modifiedOn;
	}

	/**
	 */
	public Date getModifiedOn() {
		return this.modifiedOn;
	}

	/**
	 */
	public void setInvoices(Set<Invoice> invoices) {
		this.invoices = invoices;
	}

	/**
	 */
	@JsonIgnore
	public Set<Invoice> getInvoices() {
		if (invoices == null) {
			invoices = new java.util.LinkedHashSet<com.mh.domain.Invoice>();
		}
		return invoices;
	}

	/**
	 */
	public Customer() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Customer that) {
		setId(that.getId());
		setEmail(that.getEmail());
		setFirstName(that.getFirstName());
		setLastName(that.getLastName());
		setBirthday(that.getBirthday());
		setAddress(that.getAddress());
		setCity(that.getCity());
		setCreatedBy(that.getCreatedBy());
		setCreatedOn(that.getCreatedOn());
		setModifiedBy(that.getModifiedBy());
		setModifiedOn(that.getModifiedOn());
		setInvoices(new java.util.LinkedHashSet<com.mh.domain.Invoice>(that.getInvoices()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("email=[").append(email).append("] ");
		buffer.append("firstName=[").append(firstName).append("] ");
		buffer.append("lastName=[").append(lastName).append("] ");
		buffer.append("birthday=[").append(birthday).append("] ");
		buffer.append("address=[").append(address).append("] ");
		buffer.append("city=[").append(city).append("] ");
		buffer.append("createdBy=[").append(createdBy).append("] ");
		buffer.append("createdOn=[").append(createdOn).append("] ");
		buffer.append("modifiedBy=[").append(modifiedBy).append("] ");
		buffer.append("modifiedOn=[").append(modifiedOn).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Customer))
			return false;
		Customer equalCheck = (Customer) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
